/*action create by pionner code builder*/

package com.pioneer.app.sms.define;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.hibernate.Transaction;

import com.pioneer.app.sms.timeTask.MessageMg;

import config.BaseHibernateDAO;

public class TypeDefineDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(TypeDefine.class);
	public TypeDefine findById(java.lang.Integer id){
		log.debug("getting TypeDefine instance with id: " + id);
		try {
			TypeDefine instance =(TypeDefine)getSession().get("com.pioneer.app.sms.define.TypeDefine",id);
			return instance;
		}catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	public void delete(TypeDefine persistentInstance){
		log.debug("deletting TypeDefine persistentInstance  ");
		try {
			getSession().delete(persistentInstance);
			persistentInstance.setStatus("0");
			MessageMg.addTask(persistentInstance);
			log.debug("delete successful");
		}catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	public void add(TypeDefine persistentInstance){
		log.debug("deletting TypeDefine persistentInstance  ");
		Transaction tx=null;
		try {
			tx= getSession().beginTransaction();
			getSession().save(persistentInstance);
			tx.commit();
			MessageMg.addTask(persistentInstance);
			log.debug("add successful");
		}catch (RuntimeException re) {
			log.error("get failed", re);
			tx.rollback();
			throw re;
		}
	}
	public void update(TypeDefine persistentInstance){
		log.debug("deletting TypeDefine persistentInstance  ");
		Transaction tx=null;
		try {
			getSession().clear();
			tx= getSession().beginTransaction();
			getSession().update(persistentInstance);
			tx.commit();
			MessageMg.addTask(persistentInstance);
			log.debug("update successful");
		}catch (RuntimeException re) {
			log.error("get failed", re);
			tx.rollback();
			throw re;
		}
	}
	public List findByCondition(String condition){
		log.debug("finding by condition "+condition);
		try {

			String queryString =null;
			if(null!=condition){
				queryString = "from TypeDefine where "+condition;
			}else{queryString = "from TypeDefine";
			}

			Query queryObject = getSession().createQuery(queryString);
			queryObject.setMaxResults(500);
			return queryObject.list();
		}catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	public void deleteObjs(java.lang.Integer[]ids){
		log.debug("deleting by objects ");
		Transaction tx=null;
		try {
			if(null!=ids){
				TypeDefine obj=null;
				java.lang.Integer id=null;
				tx=this.getSession().beginTransaction();
				for(int i=0;i<ids.length;i++){
					id=ids[i];
					obj=this.findById(id);
					this.delete(obj);
				}
				tx.commit();
			}
		}catch (RuntimeException re) {
			log.error("get failed", re);
			tx.rollback();
			throw re;
		}
	}
	}
